package com.zhuwhao.sample.utils;

import android.content.Context;
import android.util.DisplayMetrics;
import android.util.TypedValue;

/**
 * Created by zhuwh on 2016/12/10 0010.
 * dp sp utils
 */
public class DensityUtils {

    /**
     * dp to px
     *
     * @param context Context
     * @param dpValue dpValue
     * @return px
     */
    public static int dp2px(Context context, float dpValue) {
        DisplayMetrics dm = context.getResources().getDisplayMetrics();
        return (int) (TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dpValue, dm) + 0.5f);
    }

    /**
     * sp to px
     *
     * @param context Context
     * @param spValue spValue
     * @return px
     */
    public static int sp2px(Context context, float spValue) {
        DisplayMetrics dm = context.getResources().getDisplayMetrics();
        return (int) (TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, spValue, dm) + 0.5f);
    }
}